package cn.laixueit.utils;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class MailUtils {
    public static void sendMail() throws MessagingException {
        Properties properties = new Properties();

        //设置服务器名称
        properties.setProperty("mail.host", "smtp.163.com");
        //设置邮件传输协议
        properties.setProperty("mail.transport.protocol", "smtp");

        Session session = Session.getInstance(properties);
        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress("15618816293@163.com"));

        message.setSubject("激活邮件");

        message.setText("右键内容");

        message.setRecipient(MimeMessage.RecipientType.TO,new InternetAddress("937220832@qq.com"));

        Transport transport = session.getTransport();

        //10.设置发件人的信息
        transport.connect("smtp.163.com", "15618816293@163.com", "sss");

        transport.sendMessage(message,message.getAllRecipients());

        transport.close();
    }

    public static void main(String[] args) throws MessagingException {
        sendMail();
    }
}
